package com.wendy.controller;

import com.wendy.model.Menu;
import com.wendy.service.MenuService;
import com.wendy.web.controller.BaseController;
import com.wendy.web.response.ResponseWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhuwending
 */
@Controller
@RequestMapping(value = "/menu")
public class MenuController extends BaseController {

    @Autowired
    private MenuService menuService;

    @RequestMapping(value = "/pageList")
    @ResponseBody
    public ResponseWrapper getMenuPageList(HttpServletRequest request) {
        return menuService.getMenuPageList(requestParam2Map(request));
    }

    @PostMapping(value = "/add")
    @ResponseBody
    public ResponseWrapper addMenu(Menu menu) {
        return menuService.addMenu(menu);
    }

    @PostMapping(value = "/update")
    @ResponseBody
    public ResponseWrapper updateMenu(Menu menu) {
        return menuService.updateMenu(menu);
    }

    @PostMapping(value = "/delete")
    @ResponseBody
    public ResponseWrapper deleteMenu(Long[] idArray) throws Exception {
        return menuService.deleteMenu(idArray);
    }
}
